//
//  MTUserModel.m
//  MeToo
//
//  Created by 俊松何 on 2018/7/5.
//  Copyright © 2018年 tianxie. All rights reserved.
//

#import "MTUserModel.h"
static NSString *MTUserKey = @"MTUserJson";

@implementation MTUserLevel

@end

@implementation MTUserInfo

@end


@implementation MTUserWalletInfo

@end

@implementation  LiveStatus

@end

@implementation MTUserModel

+(void)saveCurrentUser:(MTUserModel *)user
{
    [[NSUserDefaults standardUserDefaults] setObject:[user mj_JSONString]  forKey:MTUserKey];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+(MTUserModel *)currentUser
{
    NSString *userJson = [[NSUserDefaults standardUserDefaults] objectForKey:MTUserKey];
    if(userJson == nil)
    {
        return nil;
    }else
    {
        MTUserModel *model = [MTUserModel mj_objectWithKeyValues:userJson];
        return model;
    }
}

+(void)logout
{
     [[NSUserDefaults standardUserDefaults] removeObjectForKey:MTUserKey];
     [MTUserDataManager manager].cutrrentUser = nil;
}


+(void)updateCurrentUserInfo
{
//    NSDictionary *param = @{@"userId":[MTUserModel currentUser].userId};
//    [[MTHttpTool shareTool] getPath:@"/user/info" parameters:param success:^(MTBaseData *datamodel) {
//        MTUserModel *model = [MTUserModel mj_objectWithKeyValues:datamodel.data];
//        [MTUserModel saveCurrentUser:model];
//    } failer:^(MTError *error) {
//    }];
}

@end

static MTUserDataManager *userDataManager = nil;
@implementation MTUserDataManager

+(instancetype)manager
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        userDataManager = [[MTUserDataManager alloc] init];
    });
    return userDataManager;
}

-(void)saveCurrentUser:(MTUserModel *)user
{
    [[NSUserDefaults standardUserDefaults] setObject:[user mj_JSONString]  forKey:MTUserKey];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

-(MTUserModel *)cutrrentUser
{

    NSString *userJson = [[NSUserDefaults standardUserDefaults] objectForKey:MTUserKey];
    if(userJson == nil)
    {
        return nil;
    }else
    {
        _cutrrentUser = [MTUserModel mj_objectWithKeyValues:userJson];
        return _cutrrentUser;
    }
    

}

-(void)logout
{
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:MTUserKey];
     [MTUserDataManager manager].cutrrentUser = nil;
}


@end
